package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2022/2/25
 * Time: 21:51
 * Description:
 */
public class BorrowOperation implements IOperation{

    public void work(BookList bookList) {
        System.out.println("借阅图书！");

        Scanner scanner = new Scanner(System.in);
        System.out.println("输入你要借阅的书籍:");
        String name = scanner.nextLine();

        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
               book.setBorrowed(true);
                System.out.println("借阅成功,借阅书籍信息如下：");
                System.out.println(book);
                return;
            }
        }
        System.out.println("借阅失败，没有这本书！");
    }

}
